package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 山顶洞人郑某
 * @className ShoppingCartMapper.java
 * @date 2024 02 08
 */
@Mapper
public interface ShoppingCartMapper {


    @Select("select * from sky_take_out.shopping_cart where user_id = #{userId};")
    List<ShoppingCart> listByuserId(Long userId);

    List<ShoppingCart> list(ShoppingCart shoppingCart);

    @Update("update sky_take_out.shopping_cart set number = #{number} where id = #{id}")
    void updateCountById(ShoppingCart cart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time,number) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime},#{number})")
    void insert(ShoppingCart shoppingCart);

    void sub(ShoppingCart shoppingCart);

    @Delete("delete  from shopping_cart where id = #{id}")
    void deleteById(Long id);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);


    void insertBatch(List<ShoppingCart> shoppingCartList);
}
